package org.ghost.springboot2.demo.enumeration;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

public enum WechatScopeEnum {
    /**
     * snsapi_base
     */
    SNSAPI_BASE("snsapi_base", "不弹出授权页面，直接跳转，只能获取用户openid"),
    SNSAPI_USERINFO("snsapi_userinfo", "弹出授权页面，可通过openid拿到昵称、性别、所在地。并且， 即使在未关注的情况下，只要用户授权，也能获取其信息");

    WechatScopeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static boolean exists(String code) {
        if (StringUtils.isNotBlank(code)) {
            for (WechatScopeEnum type : WechatScopeEnum.values()) {
                if (Objects.equals(type.getCode(), code)) {
                    return true;
                }
            }
        }
        return false;
    }
}
